<!doctype html>
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/modules/cms/front/include/taglib.jsp"%>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>山东林业扶贫项目</title>
  <meta name="description" content="山东林业扶贫项目">
  <meta name="keywords" content="index">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="renderer" content="webkit">
  <meta http-equiv="Cache-Control" content="no-siteapp" />
  <link rel="icon" type="image/png" href="${ctxStatic}/sdlyfp/i/favicon.png">
  <link rel="apple-touch-icon-precomposed" href="${ctxStatic}/sdlyfp/i/app-icon72x72@2x.png">
  <meta name="apple-mobile-web-app-title" content="Amaze UI" />
  <link rel="stylesheet" href="${ctxStatic}/sdlyfp/css/amazeui.min.css" />
  <link rel="stylesheet" href="${ctxStatic}/sdlyfp/css/admin.css">
  <link rel="stylesheet" href="${ctxStatic}/sdlyfp/css/app.css">
  <script src="${ctxStatic}/My97DatePicker/WdatePicker.js" type="text/javascript"></script>
  <link rel="stylesheet" href="${ctxStatic}/sweetalert/sweetalert.css">
  <script src="${ctxStatic}/sweetalert/sweetalert.min.js"></script>
  <script src="${ctxStatic}/sdlyfp/js/base.js"></script>
  
</head>

<body data-type="generalComponents">

	<!-- head -->
	<jsp:include page="head.jsp" flush="false"></jsp:include>
	
	<div class="tpl-page-container tpl-page-header-fixed">
	
	<!-- 菜单 -->
	<jsp:include page="menu.jsp" flush="false"></jsp:include>


        <div class="tpl-content-wrapper">
            <div class="tpl-content-page-title">
               	科技下乡
            </div>
            <ol class="am-breadcrumb">
                <li><a href="#" class="am-icon-home">首页</a></li> 
                <li class="am-active">科技下乡</li>
            </ol>
            <div class="tpl-portlet-components">
                <div class="portlet-title">
                    <div class="caption font-green bold">
                        <span class="am-icon-code"></span> ${not empty gtCountryInfo.id?'修改':'添加'}科技下乡信息
                    </div>
                    <div class="tpl-portlet-input tpl-fz-ml">
                        <div class="portlet-input input-small input-inline">
                            <div class="input-icon right">   
                                 </div>
                        </div>
                    </div>


                </div>
                <div class="tpl-block">

                    <div class="am-g">
                        <div class="tpl-form-body tpl-form-line">
                            <form class="am-form tpl-form-line-form" method="post" action="${ctx }/gt/gtCountryInfo/save" enctype="multipart/form-data">
                            	<!-- <input type="hidden" name="id"/> -->
                            	<input type="hidden" id="oper" name="oper"/>
                            	<input type="hidden" id="areaId" name="area.id"/>
                            	<input type="hidden" id="areaCode" name="area.code"/>
                            	<input type="hidden" id="countryInfoId" name="id" value="${gtCountryInfo.id}"/>
                            	
                            	<input type="hidden" id="menuId" name="menuId" value="${gtCountryInfo.menuId }"/>
                            	
                            	<!-- 新增时才展示组织机构 -->
                            	<c:if test="${empty gtCountryInfo.id}">
                            	<div class="am-form-group">
                                    <label for="user-name" class="am-u-sm-3 am-form-label">地区选择  </label>
                                    <div class="am-u-sm-9">
                                    	<!-- 非省级管理员时，不再展示区县 -->
							            <c:if test="${fns:getUser().area.type gt 2}">
	                                        <select id="region" data-am-selected="{btnSize: 'sm'}" onchange="showSubArea(this,'county');">
	                                        <!-- <option value="null">---请选择---</option> -->
								              <c:forEach items="${regions }" var="region">
								              	<option value="${region.code }" areaId="${region.id }">${region.name }</option>
								              </c:forEach>
								            </select>
								            
								            <!-- 市级单位以下才展示 -->
								            <c:if test="${fns:getUser().area.type gt 3}">
								            -
								            <select id="county" data-am-selected="{btnSize: 'sm'}" <!-- onchange="showSubArea(this,'town');" -->>
								              <option value="null">---请选择---</option>
								              <c:forEach items="${countys }" var="county">
								              	<option value="${county.code }" areaId="${county.id }">${county.name }</option>
								              </c:forEach>
								            </select>
								            </c:if>
							            </c:if>
							            <!-- 省级管理员时，只展示省 -->
							            <c:if test="${fns:getUser().area.type lt 3}">
							            	<select id="region" data-am-selected="{btnSize: 'sm'}">
								              	<option value="sd" areaId="370000000000">省级</option>
								            </select>
							            </c:if>
							            <%-- -
							            <select id="town" data-am-selected="{btnSize: 'sm'}">
							              <option value="null">---请选择---</option>
							              <c:forEach items="${towns }" var="town">
							              	<option value="${town.code }" areaId="${town.id }">${town.name }</option>
							              </c:forEach>
							            </select> --%>
                                    </div>
                                </div>
                                </c:if>
                            	
                                <%-- <div class="am-form-group">
                                    <label for="user-name" class="am-u-sm-3 am-form-label">科技下乡名称  </label>
                                    <div class="am-u-sm-9">
                                        <input type="text" name="name" value="${gtCountryInfo.name }" class="tpl-form-input" id="name" placeholder="请输入科技下乡名称">
                                        <!-- <small>请填写标题文字10-20字左右。</small> -->
                                    </div>
                                </div> --%>
                                <div class="am-form-group">
                                    <label for="user-name" class="am-u-sm-3 am-form-label">科技下乡日期  </label>
                                    <div class="am-u-sm-9">
                                        <%-- <input type="text" name="time" value="${gtCountryInfo.time }" class="tpl-form-input" id="time" placeholder="请输入科技下乡日期"> --%>
                                        <input id="time" name="time" type="text" readonly="readonly" maxlength="20" class="input-medium Wdate" placeholder="请选择科技下乡日期"
											value="<fmt:formatDate value="${gtCountryInfo.time}" pattern="yyyy-MM-dd"/>"
											onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:false});"/>
                                    </div>
                                </div>
                                
                                

                                <div class="am-form-group">
                                    <label class="am-u-sm-3 am-form-label">科技下乡图片 <span class="tpl-form-line-small-title"> </span></label>
                                    <div class="am-u-sm-9">
                                        <div class="am-form-group am-form-file">
                                            <div class="tpl-form-file-img">
                                                <img src="${gtCountryInfo.filePath }" alt="">
                                            </div>
                                            <button type="button" class="am-btn am-btn-danger am-btn-sm">
                                            	<i class="am-icon-cloud-upload"></i> 科技下乡附件上传
                                            </button>
                                            <input id="file" name="file" type="file" multiple>
                                        </div>
                                    </div>
                                </div>
								<div class="am-form-group">
                                    <label class="am-u-sm-3 am-form-label">主要内容 <span class="tpl-form-line-small-title"> </span></label>
                                    <div class="am-u-sm-9">
                                        <input type="text" id="content" name="content" value="${gtCountryInfo.content }" placeholder="">
                                    </div>
                                </div>
                                
                                <%-- <div class="am-form-group">
                                    <label class="am-u-sm-3 am-form-label">经办人联系方式 <span class="tpl-form-line-small-title"> </span></label>
                                    <div class="am-u-sm-9">
                                        <input type="text" id="mobile" name="mobile" value="${gtCountryInfo.mobile }" placeholder="手机号码或者座机号(格式:区号-座机号码)">
                                    </div>
                                </div> --%>

                                <div class="am-form-group">
                                    <div class="am-u-sm-9 am-u-sm-push-3">
                                        <button type="button" class="am-btn am-btn-primary tpl-btn-bg-color-success " onclick="doSubmit('list');">提交后返回</button>
										<c:if test="${empty gtCountryInfo.id }">
											<button type="button" class="am-btn am-btn-primary tpl-btn-bg-color-success " onclick="doSubmit('form');">提交后继续添加</button>
										</c:if>
										<button type="button" class="am-btn am-btn-primary tpl-btn-bg-color-success " onclick="goBack();">返回，放弃修改</button>
                                    </div>
                                </div>
                            </form>

                        </div>
                    </div>
                </div>

                    </div>
                </div>
                <div class="tpl-alert"></div>
            </div>


        </div>

    </div>

  <script src="${ctxStatic}/sdlyfp/js/jquery.min.js"></script>
  <script src="${ctxStatic}/sdlyfp/js/amazeui.min.js"></script>
  <script src="${ctxStatic}/sdlyfp/js/app.js"></script>
</body>
<script type="text/javascript">
$(document).ready(function() {
	// $(".tpl-left-nav-menu").find("li a").eq(2).addClass("active");
	
	var menuId = '${gtCountryInfo.menuId }';
	if(menuId)
	{
		$(".tpl-left-nav-menu").find("#"+menuId).addClass("active");
	}
	
	var message = "${message}";
	if(message)
	{
		var messageType = "${messageType}";
		msg(message,3000,messageType);
	}
});


function doSubmit(oper)
{
	/* if(isNull("科技下乡名称","name",'text')){return;} */
	if(isNull("科技下乡日期","time",'text')){return;}
	var countryInfoId = '${gtCountryInfo.id }';
	// 新增时校验
	if(!countryInfoId)
	{
		/* var town = $("#town").val();
		if(!town || 'null' == town || null == town)
		{
			msg("区县请选择到乡镇。",3000,"warning");
			return;
		} */
		var areaType = '${fns:getUser().area.type}';
		// 省级账号时，组织机构为自己的组织机构
		if('2' == areaType)
		{
			var areaId = $("#county").find("option:selected").attr("areaId");
			
			var areaCode = $("#county").find("option:selected").val();
			if(!areaId || 'null' == areaId)
			{
				areaId = $("#region").find("option:selected").attr("areaId");
				areaCode = $("#region").find("option:selected").val();
			}
			if(!areaId || 'null' == areaId)
			{
				areaId = '${fns:getUser().area.id}';
				areaCode = '${fns:getUser().area.code}';
			}
			$("#areaId").val(areaId);
			$("#areaCode").val(areaCode);
		}
		// 地市级账号时，组织机构为所选的地市
		if('3' == areaType)
		{
			var areaId = $("#county").find("option:selected").attr("areaId");
			var areaCode = $("#county").find("option:selected").val();
			if(!areaId || 'null' == areaId)
			{
				areaId = $("#region").find("option:selected").attr("areaId");
				areaCode = $("#region").find("option:selected").val();
			}
			
			if(!areaId || 'null' == areaId)
			{
				msg("请选择地市或区县",3000,"warning");
				return;
			}
			
			$("#areaId").val(areaId);
			$("#areaCode").val(areaCode);
		}
		// 地市级账号时，组织机构为所选的地市
		if('4' == areaType)
		{
			var areaId = $("#county").find("option:selected").attr("areaId");
			var areaCode = $("#county").find("option:selected").val();
			
			if(!areaId || 'null' == areaId)
			{
				msg("请选择区县",3000,"warning");
				return;
			}
			
			$("#areaId").val(areaId);
			$("#areaCode").val(areaCode);
		}
		
		var fileName = document.getElementById("file").value;
		if(endWith(fileName,'exe') || endWith(fileName,'bat') || endWith(fileName,'com'))
		{
			msg("图片选择文件类型错误，请重新选择",3000,"warning");
			return;
		}
		if(isNull("科技下乡图片","file",'text')){return;}
	}
	
	if(isNull("主要内容","content",'text')){return;}
	// if(isNull("经办人联系方式","mobile",'mobile')){return;}
	
	$("#oper").val(oper);
	document.forms[0].submit();
}

</script>
</html>